package com.xywy.bloodandroid.act;

import java.util.regex.Pattern;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xywy.bloodandroid.R;
import com.xywy.bloodandroid.base.BaseActivity;
import com.xywy.bloodandroid.util.Constants;
import com.xywy.bloodandroid.util.UIUtil;
/**
 * *****************************************  
* @Title: PlusInfoOneAct.java 
* @Package com.xywy.bloodandroid.act 
* @Description: TODO(加号信息的第一个界面) 
* @author smz
* @date 2015-1-12 下午5:08:48 
* @version V1.0   
*******************************************
 */
public class PlusInfoOneAct extends BaseActivity {

	private RelativeLayout left_img;
	private TextView next_tv;
	private String doctor_id;
	private String expert_id;
	
	
	private String isIDCard="^\\d{18}$";
	private EditText isaddress;
	private EditText iscard;
	private EditText isphone; 
	private EditText  isname;
	private String date;
	private String id; 

	@Override
	protected void initView(Bundle savedInstanceState) {
     setContentView(R.layout.act_plus_one);
     left_img = (RelativeLayout) findViewById(R.id.left_img);
     TextView  middle_title=(TextView) findViewById(R.id.middle_title);
     
     next_tv = (TextView) findViewById(R.id.next_tv);
     middle_title.setText("加号信息 ");
     
      isname = (EditText) findViewById(R.id.isname);
     isaddress = (EditText) findViewById(R.id.isaddress);
     iscard = (EditText) findViewById(R.id.iscard);
     isphone = (EditText) findViewById(R.id.isphone);
	}

	@Override
	protected void initListener() {
     left_img.setOnClickListener(this);
     next_tv.setOnClickListener(this);
	}

	@Override
	protected void initData() {
      doctor_id = getIntent().getStringExtra("doctor_id");
      expert_id = getIntent().getStringExtra("expert_id"); 
      date = getIntent().getStringExtra("date"); 
      id = getIntent().getStringExtra("id");
	}
	
	@Override
	public void onClick(View v) {
		super.onClick(v);
		switch (v.getId()) {
		case R.id.left_img:
			finish();
			break;
		case R.id.next_tv:
			if(checkInfo()){
				Bundle bundle=new Bundle();
				bundle.putString("doctor_id", doctor_id);
				bundle.putString("expert_id", expert_id);
				bundle.putString("date", date);
				bundle.putString("id", id);
				bundle.putString("uname", isname.getText().toString().trim()+"");
				bundle.putString("province", isaddress.getText().toString().trim()+"");
				bundle.putString("pnum", iscard.getText().toString().trim()+"");
				bundle.putString("mphone", isphone.getText().toString().trim()+"");
				enterActivity(PlusInfoTwoAct.class,bundle);
			}
			break;
		default:
			break;
		}
	}
	
	private boolean checkInfo(){
		String name=isname.getText().toString().trim();
		String address=isaddress.getText().toString().trim();
		String card=iscard.getText().toString().trim();
		String phone=isphone.getText().toString().trim();
		
		
		if(name.length()<1){
			UIUtil.showToast(context, " 请填写你的名字");
			return false;
		}
		
		
		if(address.length()<1){
			UIUtil.showToast(context, "请填写你的地址");
			return false;
		}
		if(card.length()<1){
			UIUtil.showToast(context, " 身份证号不能为空");
			return false;
		}
		if(!Pattern.matches(isIDCard,card )){
			UIUtil.showToast(context, " 身份证号输入不符合要求");
			return false;
		}
		if(phone.length()<1){
			UIUtil.showToast(context, " 手机号不能为空");
			return false;
		}
		if(!Pattern.matches(Constants.PHONE_MATCH,phone)){
			UIUtil.showToast(context, " 手机号格式不正确");
			return false;
		}
		
		return true;
	}

}
